//提现配置
import React from 'react'
import {Badge, Descriptions, message, Space} from 'antd';
import EditInput from "./component/editInput";
import {getSharerWithdrawalConfig, setSharerWithdrawalConfig} from "@/request/distribution/withdrawSetting";

export default class WithdrawSetting extends React.Component {
    state = {
        lowerLevelMinimumAmount: 0, // 初级分享官-单次最低金额(单位分)
        highLevelMinimumAmount: 0, // 高级分享官-单次最低金额(单位分)
        manualAuditThreshold: 0, // 提现金额触达人工审核的额度(单位分)
        dayNumber: 0, // 单日最大次数
        configId: null
    }

    componentDidMount() {
        this.getData()
    }

    getData = () => {
        getSharerWithdrawalConfig().then(res => {
            if (res.code === 0) {
                this.setState({
                    lowerLevelMinimumAmount: res.data.lowerLevelMinimumAmount,
                    highLevelMinimumAmount: res.data.highLevelMinimumAmount,
                    manualAuditThreshold: res.data.manualAuditThreshold,
                    dayNumber: res.data.dayNumber,
                    configId: res.data.configId
                })
            }
        })
    }
    onSave = async (v, key) => {
        let params = {
            configId: this.state.configId,
            [key]: v
        }
        let res = await setSharerWithdrawalConfig({...params})
        if (res.code === 0){
            message.success('修改成功')
        }
        return res.success
    }

    render() {
        let {
            lowerLevelMinimumAmount,
            highLevelMinimumAmount,
            manualAuditThreshold,
            dayNumber
        } = this.state
        return (
            <div className='p-layout-box commodity-content'>
                <Descriptions title="分享官分佣账户提现配置" layout="vertical" bordered>
                    <Descriptions.Item label="单次提现最低金额（元）" style={{width: '33%'}}>
                        <Space direction={'vertical'}>
                            <Space>
                                <span>初级分享官</span>
                                <EditInput
                                    min={0.1}
                                    max={999999.99}
                                    precision={2}
                                    defaultValue={lowerLevelMinimumAmount}
                                    onSave={(v) => this.onSave(v, 'lowerLevelMinimumAmount')}
                                    type={'price'}
                                    haspermi={['distribution:withdrawSetting:lowerLevel']}
                                />
                            </Space>
                            <Space>
                                <span>高级分享官</span>
                                <EditInput
                                    min={0.1}
                                    max={999999.99}
                                    precision={2}
                                    defaultValue={highLevelMinimumAmount}
                                    onSave={(v) => this.onSave(v, 'highLevelMinimumAmount')}
                                    type={'price'}
                                    haspermi={['distribution:withdrawSetting:highLevel']}
                                />
                            </Space>
                        </Space>
                    </Descriptions.Item>
                    <Descriptions.Item label="提现金额触达人工审核的额度（元）" style={{width: '33%'}}>
                        <EditInput
                            min={0.01}
                            max={999999.99}
                            precision={2}
                            defaultValue={manualAuditThreshold}
                            onSave={(v) => this.onSave(v, 'manualAuditThreshold')}
                            type={'price'}
                            haspermi={['distribution:withdrawSetting:manual']}
                        />
                    </Descriptions.Item>
                    <Descriptions.Item label="单日提现次数（次）" style={{width: '33%'}}>
                        <EditInput
                            min={1}
                            max={10000}
                            precision={0}
                            defaultValue={dayNumber}
                            addonAfter={'次'}
                            onSave={(v) => this.onSave(v, 'dayNumber')}
                            haspermi={['distribution:withdrawSetting:dayNumber']}
                        />
                    </Descriptions.Item>
                </Descriptions>
            </div>
        )
    }
}
